from time import sleep
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
# 1.打开浏览器
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.wait import WebDriverWait

driver = webdriver.Chrome(executable_path='chromedriver.exe')
# 2.输入访问地址（URL）
url = r"D:\UI自动化测试\注册实例.html"
driver.get(url)


# 1). 填写主页面的注册信息
sleep(3)
driver.find_element_by_css_selector("#user").send_keys("admin")# 用户名
driver.find_element_by_css_selector("#password").send_keys("123456")# 密码
driver.find_element_by_css_selector("#tel").send_keys("17866564545")# 电话号码
driver.find_element_by_css_selector("#email").send_keys("12345@qq.com")# 电子邮件

handles = driver.current_window_handle# 获取当前窗口句柄

# 点击‘注册A页面’链接
driver.find_element_by_partial_link_text("A网页").click()

sleep(3)
for window_handle in driver.window_handles:
    if window_handle != handles:
        driver.switch_to.window(window_handle)
        break
# 2). 填写注册页面A中的注册信息
# 方法1
driver.find_element_by_css_selector("#userA").send_keys("admin1")# 用户名
driver.find_element_by_css_selector("#passwordA").send_keys("123456")# 密码
driver.find_element_by_css_selector("#telA").send_keys("18866564545")# 电话号码
driver.find_element_by_css_selector("#emailA").send_keys("1234@qq.com")# 电子邮件
# 方法2
# driver.find_element(By.CSS_SELECTOR, "#userA").send_keys("admin1")# 用户名
# driver.find_element(By.CSS_SELECTOR, "#passwordA").send_keys("123456")# 密码
# driver.find_element(By.CSS_SELECTOR, "#telA").send_keys("18866564545")# 电话号码
# driver.find_element(By.CSS_SELECTOR, "#emailA").send_keys("1234@qq.com")# 电子邮件

sleep(3)
driver.quit()


